#include "StdAfx.h"
#include "NaturalSplineEditor.h"
#include "SphereArrayEditor.h"
#include "SEPEditor.h"

namespace SEPEditor
{

	System::Object^ UINaturalSplineEditor::EditValue(ITypeDescriptorContext^ context,
								  System::IServiceProvider^ provider, System::Object^ value)
{
	if (context == nullptr || provider == nullptr || context->Instance == nullptr)
		return System::Drawing::Design::UITypeEditor::EditValue(provider, value);

	PropertyGridEx::PropertyBag::PropertySpecDescriptor^ splinedesc=(PropertyGridEx::PropertyBag::PropertySpecDescriptor^)context->PropertyDescriptor;

	NaturalSplineObjectProp^ obj=(NaturalSplineObjectProp^)(((MyPropertyTable^)(splinedesc->bag))[context->PropertyDescriptor->Name]);
	NaturalSplineEditor^ se=gcnew NaturalSplineEditor(obj,context->PropertyDescriptor->Name);
	se->Show(SEPEditorForm::mainForm->getDockPanel(),WeifenLuo::WinFormsUI::Docking::DockState::DockBottom);
	return value;
}

	System::Void NaturalSplineEditor::NaturalSplineEditor_Shown(System::Object^  sender, System::EventArgs^  e) {
		SEPEditorForm::mainForm->act_propeditor=this->mouseeventhandler;
		SEPEditorForm::mainForm->opModeChanged(op_propertyedit);
		 }

	System::Void NaturalSplineEditor::NaturalSplineEditor_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {

		if (SEPEditorForm::mainForm->act_propeditor==this->mouseeventhandler)
		{
			SEPEditorForm::mainForm->act_propeditor=nullptr;
			SEPEditorForm::mainForm->opModeChanged(op_selection);
		}

		obj->set_selected_index(0);
	}

	System::Void NaturalSplineEditor::NaturalSplineEditor_Enter(System::Object^  sender, System::EventArgs^  e)
	{
		SEPEditorForm::mainForm->act_propeditor=this->mouseeventhandler;
		SEPEditorForm::mainForm->opModeChanged(op_propertyedit);
	}


	System::Void NaturalSplineEditor::InvalidateRenderViews()
	{
		SEPEditorForm::mainForm->invalidate_all_views();
	}







	System::Object^ UISphereArrayEditor::EditValue(ITypeDescriptorContext^ context,
		System::IServiceProvider^ provider, System::Object^ value)
	{
		if (context == nullptr || provider == nullptr || context->Instance == nullptr)
			return System::Drawing::Design::UITypeEditor::EditValue(provider, value);

		PropertyGridEx::PropertyBag::PropertySpecDescriptor^ splinedesc=(PropertyGridEx::PropertyBag::PropertySpecDescriptor^)context->PropertyDescriptor;

		SphereArrayProp^ obj=(SphereArrayProp^)(((MyPropertyTable^)(splinedesc->bag))[context->PropertyDescriptor->Name]);
		SphereArrayEditor^ se=gcnew SphereArrayEditor(obj);
		se->Show(SEPEditorForm::mainForm->getDockPanel(),WeifenLuo::WinFormsUI::Docking::DockState::DockBottom);
		return value;
	}

	System::Void SphereArrayEditor::SphereArrayEditor_Shown(System::Object^  sender, System::EventArgs^  e) {
		SEPEditorForm::mainForm->act_propeditor=this->mouseeventhandler;
		SEPEditorForm::mainForm->opModeChanged(op_propertyedit);
	}

	System::Void SphereArrayEditor::SphereArrayEditor_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {

		if (SEPEditorForm::mainForm->act_propeditor==this->mouseeventhandler)
		{
			SEPEditorForm::mainForm->act_propeditor=nullptr;
			SEPEditorForm::mainForm->opModeChanged(op_selection);
		}

		for (unsigned n=0; n<obj->sphere_array->size(); ++n)
			(*obj->sphere_array)[n].selected=false;
	}







}
